#!/bin/bash
source .env

# curl -u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD} -k http://localhost:9200

# 现要创建一个角色，具有monitor和manage的权限
curl -u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD} -k -XPUT "http://localhost:9200/_security/role/cluster" -H "Content-Type: application/json" -d '{
 "cluster": [
   "monitor",
   "manage"
 ],
 "indices": [
 ],
 "run_as": [],
 "metadata": {},
 "transient_metadata": {
   "enabled": true
 }
}'

# 然后创建一个user
curl -u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD} -k -XPUT "http://localhost:9200/_security/user/cluster" -H "Content-Type: application/json" -d '{
   "password": "${KIBANA_PASSWORD}",
   "roles": ["cluster"]
 }'



#curl -u elastic:0j9hkNvfULXrng9KywYR -k -XPUT "http://localhost:9200/_security/role/cluster" -H "Content-Type: application/json" -d '{
# "cluster": [
#   "monitor",
#   "manage"
# ],
# "indices": [
# ],
# "run_as": [],
# "metadata": {},
# "transient_metadata": {
#   "enabled": true
# }
#}'
#curl -u elastic:0j9hkNvfULXrng9KywYR -k -XPUT "http://localhost:9200/_security/user/cluster" -H "Content-Type: application/json" -d '{
#   "password": "V14Gk@sB*>N!#0}9",
#   "roles": ["cluster"]
# }'
#docker run --name kibana -e ELASTICSEARCH_HOSTS=http://35.170.190.90/:9200 \
#   -p 5601:5601 \
#   kibana:8.14.3